<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<jsp:useBean id="databaseBean" scope="session"
	class="warehouse.DatabaseBean" />

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>仓库详情</title>

<link rel="stylesheet" href="layui/css/layui.css">
<script src="layui/layui.js"></script>
</head>
<body>
	<a href="warehouse_list.jsp" class="layui-btn"><i class="layui-icon layui-icon-return"></i>返回仓库列表</a>
	<%
		String warehouseNoString = request.getParameter("warehouseNo");

		if (warehouseNoString == null) {
			//如果没有传入此参数，则跳转到仓库一览表
			response.sendRedirect("warehouse_list.jsp");
		}
	%>
	<h1 style="text-align: center">仓库详情</h1>
	<div class="layui-tab layui-tab-brief">
		<ul class="layui-tab-title">
			<li class="layui-this">仓库信息</li>
			<li>货物库存</li>
			<li>职工</li>
		</ul>
		<div class="layui-tab-content">
			<!-- 仓库信息 -->
			<div class="layui-tab-item layui-show">
			<table class="layui-table" lay-even>
				<thead>
				<tr>
					<th>仓库编号</th>
					<th>仓库地址</th>
				</tr>
				</thead>
			<%
				String sql=String.format("SELECT * FROM Warehouse WHERE warehouseNo='%s';", warehouseNoString);
				ResultSet rs=databaseBean.executeQuery(sql);
				while(rs.next()){
					%>
					<tr>
						<td><%=rs.getString("warehouseNo")  %>	</td>
						<td><%=rs.getString("address")  %>		</td>
					</tr>		
					<%
				}
				rs.close();
				%>
			</table>
			
			</div>
			<!-- 货物库存 -->
			<div class="layui-tab-item">
			<table class="layui-table" lay-even>
				<thead>
				<tr>
					<th>货物编号</th>
					<th>名称</th>
					<th>单价(元)</th>
					<th>库存量(件)</th>
				</tr>
				</thead>
			<%
				sql=String.format("SELECT cargoNo,name,price,inventory FROM Cargo WHERE warehouseNo='%s';",warehouseNoString);
				rs=databaseBean.executeQuery(sql);
				while(rs.next()){
					%>
					<tr>
						<td><%=rs.getString("cargoNo")  %>	</td>
						<td><%=rs.getString("name")  %>		</td>
						<td><%=rs.getString("price")  %>		</td>
						<td><%=rs.getString("inventory")  %>		</td>
					</tr>		
					<%
				}
				rs.close();
				%>
			</table>
			
			</div>
			<!-- 职工信息 -->
			<div class="layui-tab-item">
				<table class="layui-table" lay-even>
				<thead>
				<tr>
					<th>职工号</th>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>电话号码</th>
					
				</tr>
				</thead>
				<%
					sql=String.format("SELECT staffNo,name,gender,age,telenumber FROM staff WHERE warehouseNo='%s';",warehouseNoString);
					rs=databaseBean.executeQuery(sql);
					while(rs.next()){
						%>
						<tr>
							<td><%=rs.getString("staffNo")  %>	</td>
							<td><%=rs.getString("name")  %>		</td>
							<td><%="M".equals(rs.getString("gender"))?"男":"女"%></td>
							<td><%=rs.getString("age")  %>		</td>
							<td><%=rs.getString("telenumber")  %>		</td>
						</tr>		
						<%
					}
					rs.close();
					%>
				</table>
			</div>

		</div>
	</div>

	<script>
		//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
		layui.use('element', function() {
			var element = layui.element;
		});
	</script>
	
</body>
</html>